package com.yh.homestay.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.common.SysLogRustlt;
import com.yh.homestay.dao.LogListMapper;
import com.yh.homestay.dao.SysLogMapper;
import com.yh.homestay.pojo.SysLog;
import com.yh.homestay.service.LogModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LogModelServiceImpl implements LogModelService {
    @Autowired
    private SysLogMapper sysLogMapper;//通用mapper
    @Autowired
    private LogListMapper logListMapper;//只做展示和模糊查询mapper
    //向数据库添加日志
    @Override
    public int addLogModel(SysLog logModel) {
       int  add=sysLogMapper.insert(logModel);
        return add;
    }
    //查询数据库中的日志操作
    @Override
    public HomeStayResult selecteAllLogs(Integer page, Integer limit, String start, String end, String logAccessAccount) {
        Map map=new HashMap();
        map.put("start",start);
        map.put("end",end);
        map.put("logAccessAccount",logAccessAccount);
        PageHelper.startPage(page,limit);
        List<SysLog> list=logListMapper.listLogs(map);
        PageInfo info=new PageInfo(list);
        return new HomeStayResult(0,"OK",(int)info.getTotal(),info.getList());
    }

    @Override
    public SysLogRustlt selecteLogByLogId(Integer num) {
        SysLog log=new SysLog();
        log.setLogId(num);
        SysLog a=sysLogMapper.selectOne(log);

        SysLogRustlt res=new SysLogRustlt(200,"success",a);
        return res;
    }


}
